Type.registerNamespace('ModWatch');

ModWatch.ModAlertRadioButtonGroup = function()
{
	ModWatch.ModAlertRadioButtonGroup.initializeBase(this);

	this._groupName = '';
	this._radioButtons = new Array();
}

ModWatch.ModAlertRadioButtonGroup.prototype = {

	get_groupName : function()
	{
		return this._groupName;
	},

	set_groupName : function(value)
	{
		this._groupName = value;
	},

	addRadioButton : function(radioButton)
	{
		Array.add(this._radioButtons, radioButton);
	},

	removeRadioButton : function(radioButton)
	{
		Array.remove(this._radioButtons, radioButton);
	},

	revertToSavedValues : function()
	{
		var revertValue = function(element, index, array)
		{
			if (element)
				element.revertToSavedValue();
		};
		
		Array.forEach(this._radioButtons, revertValue, null);
	},

	saveCurrentValues : function()
	{
		var saveValue = function(element, index, array)
		{
			if (element)
				element.saveCurrentValue();
		};

		Array.forEach(this._radioButtons, saveValue, null);
	}

}

ModWatch.ModAlertRadioButtonGroup.registerClass('ModWatch.ModAlertRadioButtonGroup', Sys.Component);


ModWatch.ModAlertRadioButtonTracker = function()
{
	ModWatch.ModAlertRadioButtonTracker.initializeBase(this);

	this._radioButtonGroups = new Array();
}

ModWatch.ModAlertRadioButtonTracker.prototype = {

	addRadioButton : function(radioButton, groupName)
	{
		var group = null;

		for (var i = 0; i < this._radioButtonGroups.length; i++)
		{
			if (this._radioButtonGroups[i].get_groupName() == groupName)
			{
				group = this._radioButtonGroups[i];
				break;
			}
		}

		if (group == null)
		{
			group = $create(ModWatch.ModAlertRadioButtonGroup);
			group.set_groupName(groupName);
			Array.add(this._radioButtonGroups, group);
		}
		
		group.addRadioButton(radioButton);
	},
	
	removeRadioButton : function(radioButton, groupName)
	{
		for (var i = 0; i < this._radioButtonGroups.length; i++)
		{
			if (this._radioButtonGroups[i].get_groupName() == groupName)
			{
				this._radioButtonGroups[i].removeRadioButton(radioButton);
				break;
			}
		}
	},

	revertToSavedValues : function(radioButton, groupName)
	{
		if (!groupName || groupName == '')
		{
			radioButton.revertToSavedValue();
		}
		else
		{
			for (var i = 0; i < this._radioButtonGroups.length; i++)
			{
				if (this._radioButtonGroups[i].get_groupName() == groupName)
				{
					this._radioButtonGroups[i].revertToSavedValues(radioButton);
					break;
				}
			}
		}
    },

	saveCurrentValues : function(radioButton, groupName)
	{
		if (!groupName || groupName == '')
		{
			radioButton.saveCurrentValue();
		}
		else
		{
			for (var i = 0; i < this._radioButtonGroups.length; i++)
			{
				if (this._radioButtonGroups[i].get_groupName() == groupName)
				{
					this._radioButtonGroups[i].saveCurrentValues(radioButton);
					break;
				}
			}
		}
	}

}

ModWatch.ModAlertRadioButtonTracker.registerClass('ModWatch.ModAlertRadioButtonTracker', Sys.Component);

if (!ModWatch.ModAlertRadioButtonTrackerInstance)
	ModWatch.ModAlertRadioButtonTrackerInstance = $create(ModWatch.ModAlertRadioButtonTracker, null, null, null, null);

if (typeof(Sys) !== 'undefined')
	Sys.Application.notifyScriptLoaded();
